﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Catering_DBOpertion;

namespace Catering_Operation
{
    /// <summary>
    /// 数据访问类:Group_Nutrien
    /// </summary>
    public partial class Group_Nutrien
    {
        public Group_Nutrien()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("id", "Group_Nutrien");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Group_Nutrien");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.Group_Nutrien model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Group_Nutrien(");
            strSql.Append("GroupID,AreaID,ClassID,Kka,Kjiao,Danbaizhi,zhifang,va,huangchun,vb1,vb2,nikesuan,vc,huluobo,gai,tie,xin,back,temp1,temp2)");
            strSql.Append(" values (");
            strSql.Append("@GroupID,@AreaID,@ClassID,@Kka,@Kjiao,@Danbaizhi,@zhifang,@va,@huangchun,@vb1,@vb2,@nikesuan,@vc,@huluobo,@gai,@tie,@xin,@back,@temp1,@temp2)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@GroupID", SqlDbType.Int,4),
					new SqlParameter("@AreaID", SqlDbType.Int,4),
					new SqlParameter("@ClassID", SqlDbType.Int,4),
					new SqlParameter("@Kka", SqlDbType.Float,8),
					new SqlParameter("@Kjiao", SqlDbType.Float,8),
					new SqlParameter("@Danbaizhi", SqlDbType.Float,8),
					new SqlParameter("@zhifang", SqlDbType.Float,8),
					new SqlParameter("@va", SqlDbType.Float,8),
					new SqlParameter("@huangchun", SqlDbType.Float,8),
					new SqlParameter("@vb1", SqlDbType.Float,8),
					new SqlParameter("@vb2", SqlDbType.Float,8),
					new SqlParameter("@nikesuan", SqlDbType.Float,8),
					new SqlParameter("@vc", SqlDbType.Float,8),
					new SqlParameter("@huluobo", SqlDbType.Float,8),
					new SqlParameter("@gai", SqlDbType.Float,8),
					new SqlParameter("@tie", SqlDbType.Float,8),
					new SqlParameter("@xin", SqlDbType.Float,8),
					new SqlParameter("@back", SqlDbType.VarChar,50),
					new SqlParameter("@temp1", SqlDbType.VarChar,200),
					new SqlParameter("@temp2", SqlDbType.VarChar,200)};
            parameters[0].Value = model.GroupID;
            parameters[1].Value = model.AreaID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.Kka;
            parameters[4].Value = model.Kjiao;
            parameters[5].Value = model.Danbaizhi;
            parameters[6].Value = model.zhifang;
            parameters[7].Value = model.va;
            parameters[8].Value = model.huangchun;
            parameters[9].Value = model.vb1;
            parameters[10].Value = model.vb2;
            parameters[11].Value = model.nikesuan;
            parameters[12].Value = model.vc;
            parameters[13].Value = model.huluobo;
            parameters[14].Value = model.gai;
            parameters[15].Value = model.tie;
            parameters[16].Value = model.xin;
            parameters[17].Value = model.back;
            parameters[18].Value = model.temp1;
            parameters[19].Value = model.temp2;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.Group_Nutrien model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Group_Nutrien set ");
            strSql.Append("GroupID=@GroupID,");
            strSql.Append("AreaID=@AreaID,");
            strSql.Append("ClassID=@ClassID,");
            strSql.Append("Kka=@Kka,");
            strSql.Append("Kjiao=@Kjiao,");
            strSql.Append("Danbaizhi=@Danbaizhi,");
            strSql.Append("zhifang=@zhifang,");
            strSql.Append("va=@va,");
            strSql.Append("huangchun=@huangchun,");
            strSql.Append("vb1=@vb1,");
            strSql.Append("vb2=@vb2,");
            strSql.Append("nikesuan=@nikesuan,");
            strSql.Append("vc=@vc,");
            strSql.Append("huluobo=@huluobo,");
            strSql.Append("gai=@gai,");
            strSql.Append("tie=@tie,");
            strSql.Append("xin=@xin,");
            strSql.Append("back=@back,");
            strSql.Append("temp1=@temp1,");
            strSql.Append("temp2=@temp2");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@GroupID", SqlDbType.Int,4),
					new SqlParameter("@AreaID", SqlDbType.Int,4),
					new SqlParameter("@ClassID", SqlDbType.Int,4),
					new SqlParameter("@Kka", SqlDbType.Float,8),
					new SqlParameter("@Kjiao", SqlDbType.Float,8),
					new SqlParameter("@Danbaizhi", SqlDbType.Float,8),
					new SqlParameter("@zhifang", SqlDbType.Float,8),
					new SqlParameter("@va", SqlDbType.Float,8),
					new SqlParameter("@huangchun", SqlDbType.Float,8),
					new SqlParameter("@vb1", SqlDbType.Float,8),
					new SqlParameter("@vb2", SqlDbType.Float,8),
					new SqlParameter("@nikesuan", SqlDbType.Float,8),
					new SqlParameter("@vc", SqlDbType.Float,8),
					new SqlParameter("@huluobo", SqlDbType.Float,8),
					new SqlParameter("@gai", SqlDbType.Float,8),
					new SqlParameter("@tie", SqlDbType.Float,8),
					new SqlParameter("@xin", SqlDbType.Float,8),
					new SqlParameter("@back", SqlDbType.VarChar,50),
					new SqlParameter("@temp1", SqlDbType.VarChar,200),
					new SqlParameter("@temp2", SqlDbType.VarChar,200),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.GroupID;
            parameters[1].Value = model.AreaID;
            parameters[2].Value = model.ClassID;
            parameters[3].Value = model.Kka;
            parameters[4].Value = model.Kjiao;
            parameters[5].Value = model.Danbaizhi;
            parameters[6].Value = model.zhifang;
            parameters[7].Value = model.va;
            parameters[8].Value = model.huangchun;
            parameters[9].Value = model.vb1;
            parameters[10].Value = model.vb2;
            parameters[11].Value = model.nikesuan;
            parameters[12].Value = model.vc;
            parameters[13].Value = model.huluobo;
            parameters[14].Value = model.gai;
            parameters[15].Value = model.tie;
            parameters[16].Value = model.xin;
            parameters[17].Value = model.back;
            parameters[18].Value = model.temp1;
            parameters[19].Value = model.temp2;
            parameters[20].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Group_Nutrien ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Group_Nutrien ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.Group_Nutrien GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,GroupID,AreaID,ClassID,Kka,Kjiao,Danbaizhi,zhifang,va,huangchun,vb1,vb2,nikesuan,vc,huluobo,gai,tie,xin,back,temp1,temp2 from Group_Nutrien ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
            parameters[0].Value = id;

            Catering_Model.Group_Nutrien model = new Catering_Model.Group_Nutrien();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["GroupID"] != null && ds.Tables[0].Rows[0]["GroupID"].ToString() != "")
                {
                    model.GroupID = int.Parse(ds.Tables[0].Rows[0]["GroupID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["AreaID"] != null && ds.Tables[0].Rows[0]["AreaID"].ToString() != "")
                {
                    model.AreaID = int.Parse(ds.Tables[0].Rows[0]["AreaID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ClassID"] != null && ds.Tables[0].Rows[0]["ClassID"].ToString() != "")
                {
                    model.ClassID = int.Parse(ds.Tables[0].Rows[0]["ClassID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Kka"] != null && ds.Tables[0].Rows[0]["Kka"].ToString() != "")
                {
                    model.Kka = decimal.Parse(ds.Tables[0].Rows[0]["Kka"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Kjiao"] != null && ds.Tables[0].Rows[0]["Kjiao"].ToString() != "")
                {
                    model.Kjiao = decimal.Parse(ds.Tables[0].Rows[0]["Kjiao"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Danbaizhi"] != null && ds.Tables[0].Rows[0]["Danbaizhi"].ToString() != "")
                {
                    model.Danbaizhi = decimal.Parse(ds.Tables[0].Rows[0]["Danbaizhi"].ToString());
                }
                if (ds.Tables[0].Rows[0]["zhifang"] != null && ds.Tables[0].Rows[0]["zhifang"].ToString() != "")
                {
                    model.zhifang = decimal.Parse(ds.Tables[0].Rows[0]["zhifang"].ToString());
                }
                if (ds.Tables[0].Rows[0]["va"] != null && ds.Tables[0].Rows[0]["va"].ToString() != "")
                {
                    model.va = decimal.Parse(ds.Tables[0].Rows[0]["va"].ToString());
                }
                if (ds.Tables[0].Rows[0]["huangchun"] != null && ds.Tables[0].Rows[0]["huangchun"].ToString() != "")
                {
                    model.huangchun = decimal.Parse(ds.Tables[0].Rows[0]["huangchun"].ToString());
                }
                if (ds.Tables[0].Rows[0]["vb1"] != null && ds.Tables[0].Rows[0]["vb1"].ToString() != "")
                {
                    model.vb1 = decimal.Parse(ds.Tables[0].Rows[0]["vb1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["vb2"] != null && ds.Tables[0].Rows[0]["vb2"].ToString() != "")
                {
                    model.vb2 = decimal.Parse(ds.Tables[0].Rows[0]["vb2"].ToString());
                }
                if (ds.Tables[0].Rows[0]["nikesuan"] != null && ds.Tables[0].Rows[0]["nikesuan"].ToString() != "")
                {
                    model.nikesuan = decimal.Parse(ds.Tables[0].Rows[0]["nikesuan"].ToString());
                }
                if (ds.Tables[0].Rows[0]["vc"] != null && ds.Tables[0].Rows[0]["vc"].ToString() != "")
                {
                    model.vc = decimal.Parse(ds.Tables[0].Rows[0]["vc"].ToString());
                }
                if (ds.Tables[0].Rows[0]["huluobo"] != null && ds.Tables[0].Rows[0]["huluobo"].ToString() != "")
                {
                    model.huluobo = decimal.Parse(ds.Tables[0].Rows[0]["huluobo"].ToString());
                }
                if (ds.Tables[0].Rows[0]["gai"] != null && ds.Tables[0].Rows[0]["gai"].ToString() != "")
                {
                    model.gai = decimal.Parse(ds.Tables[0].Rows[0]["gai"].ToString());
                }
                if (ds.Tables[0].Rows[0]["tie"] != null && ds.Tables[0].Rows[0]["tie"].ToString() != "")
                {
                    model.tie = decimal.Parse(ds.Tables[0].Rows[0]["tie"].ToString());
                }
                if (ds.Tables[0].Rows[0]["xin"] != null && ds.Tables[0].Rows[0]["xin"].ToString() != "")
                {
                    model.xin = decimal.Parse(ds.Tables[0].Rows[0]["xin"].ToString());
                }
                if (ds.Tables[0].Rows[0]["back"] != null && ds.Tables[0].Rows[0]["back"].ToString() != "")
                {
                    model.back = ds.Tables[0].Rows[0]["back"].ToString();
                }
                if (ds.Tables[0].Rows[0]["temp1"] != null && ds.Tables[0].Rows[0]["temp1"].ToString() != "")
                {
                    model.temp1 = ds.Tables[0].Rows[0]["temp1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["temp2"] != null && ds.Tables[0].Rows[0]["temp2"].ToString() != "")
                {
                    model.temp2 = ds.Tables[0].Rows[0]["temp2"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,GroupID,AreaID,ClassID,Kka,Kjiao,Danbaizhi,zhifang,va,huangchun,vb1,vb2,nikesuan,vc,huluobo,gai,tie,xin,back,temp1,temp2 ");
            strSql.Append(" FROM Group_Nutrien ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,GroupID,AreaID,ClassID,Kka,Kjiao,Danbaizhi,zhifang,va,huangchun,vb1,vb2,nikesuan,vc,huluobo,gai,tie,xin,back,temp1,temp2 ");
            strSql.Append(" FROM Group_Nutrien ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Group_Nutrien";
            parameters[1].Value = "id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}
